
// 初始化主编辑器
function initMainEditor() {
    const mainTextarea = document.querySelector('.message-form textarea[name="content"]');
    if (mainTextarea && !mainTextarea.classList.contains('froala-initialized')) {
        new FroalaEditor(mainTextarea, {
            language: 'zh_cn',
            // 其他配置...
        });
        mainTextarea.classList.add('froala-initialized');
    }
}

// 初始化回复编辑器（使用事件委托）
document.addEventListener('click', function(e) {
    // 当点击回复区域时初始化
    if (e.target.closest('.reply-form-container')) {
        const replyTextareas = document.querySelectorAll('.reply-form textarea[name="content"]:not(.froala-initialized)');
        replyTextareas.forEach(textarea => {
            new FroalaEditor(textarea, {
                language: 'zh_cn',
                toolbarButtons: ['bold', 'italic', 'underline', 'emoticons', 'insertImage'],
                imageUploadURL: '{{ url_for("messages.upload_image") }}',
                heightMin: 100,
                placeholderText: '回复...'
            });
            textarea.classList.add('froala-initialized');
        });
    }
});

// 初始加载时初始化可见的编辑器
document.addEventListener('DOMContentLoaded', function() {
    initMainEditor();

    // 初始化已经存在的回复表单
    document.querySelectorAll('.reply-form textarea[name="content"]:not(.froala-initialized)').forEach(textarea => {
        new FroalaEditor(textarea, {
            // 回复编辑器配置...
        });
        textarea.classList.add('froala-initialized');
    });
});